package Thread;

public class Demo39 {
    private static int sum = 0;
    public static void main(String[] args) throws InterruptedException {
        //创建一个线程,用来实现 1+2+3+4+ ... + 1000
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                int result = 0;
                for(int i = 1; i <= 1000 ; i++){
                    result += i ;
                }
                //此处,为了把 result 结果告诉主线程,就需要通过成员变量sum来获取一下
                sum = result;
            }
        });
        t.start();
        t.join();

        //主线程获取到的结果
        System.out.println(sum);
        
    }
}
